<?php
class Utilities {
    
    /**
     * $strDateTime Date string in the format yyyy-mm-dd HH:MM:SS
     */
    public static function getTimestampFromMySqlDatetime($strDatetime) {
	    $ar = explode(" ", $strDatetime);
        if (count($ar) != 2) {
            return 0;
	    }
        $dateStr = $ar[0];
        $timeStr = $ar[1];
        
        $arDate = explode("-", $dateStr);        
	    if (count($arDate) != 3) {
            return 0;
	    }
        
        $date = (int) $arDate[2];
        $month = (int) $arDate[1];
        $year = (int) $arDate[0];
        
	    if ($month < 0 || $month > 12) { 
            return 0;
	    }
	    if ($date < 0 || $date > 31) { 
            return 0;
	    }
        
        $arTime = explode(":", $timeStr);        
	    if (count($arTime) != 3) {
            return 0;
	    }
	    $timestamp = mktime((int) $arTime[0], (int) $arTime[1], (int) $arTime[2],
                            $month, $date, $year);
	    return $timestamp;
	}    
    
    
    /**
     * $strDate Date string in the format yyyy-mm-dd
     */
    public static function getTimestampFromMySqlDate($strDate) {
	    $ar = explode("-", $strDate);
	    if (count($ar) != 3) {
            return 0;
	    }
        $date = (int) $strDate[2];
        $month = (int) $strDate[1];
        $year = (int) $strDate[0];
        
	    if ($month < 0 || $month > 12) { 
            return 0;
	    }
	    if ($date < 0 || $date > 31) { 
            return 0;
	    }
	    $timestamp = mktime(0,0,0, $month, $date, $year);
	    return $timestamp;
	}
    
    
    /**
     * $strDate Date string in the format dd-mm-yyyy
     */    
	public static function getTimestamp($strDate) {
	    $ar = explode("-", $strDate);
	    if (count($ar) != 3) {
            return 0;
	    }
	    if ($ar[1] < 0 || $ar[1] > 12) { 
            return 0;
	    }
	    if ($ar[0] < 0 || $ar[1] > 31) { 
            return 0;
	    }	    
	    $timestamp = mktime(0,0,0, $ar[1], $ar[0], $ar[2],0);
	    return $timestamp;
	}    
}
?>